package com.home766.controller.admin;

import com.home766.entity.CustomerServicePage;
import com.home766.service.CustomerServicePageService;
import net.biz.Message;
import net.biz.Message.Type;
import net.biz.controller.admin.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("/admin/customerServicePage")
public class CustomerServicePageController extends BaseController {
	@Autowired
	private CustomerServicePageService customerServicePageService;
	/***
	 * 页面跳转
	 * @return
	 */
	@RequestMapping("/pageReturn")
	public String pageReturn(ModelMap modelMap){
		List<CustomerServicePage> list = customerServicePageService.findAll();
		modelMap.addAttribute("list",list);
		return "/admin/customerServicePage/content";
	}
	@RequestMapping("/add")
	public String add(CustomerServicePage customerServicePage, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes){
		if(customerServicePage.getId()!=null){
			customerServicePageService.update(customerServicePage);
			addFlashMessage(redirectAttributes,new Message(Type.success,"修改成功"));
		}else{
			customerServicePageService.save(customerServicePage);
			addFlashMessage(redirectAttributes,new Message(Type.success,"保存成功"));
		}
		return "redirect:pageReturn.jhtml";
	}
}
